<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input name="c_id" id="c_id" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label required">车辆名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="car_name" lay-verify="required" lay-reqtext="车辆名称不能为空" placeholder="请输入车辆名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">操作方式</label>
        <div class="layui-input-block">
            <input type="text" id="pass" name="car_type" lay-verify="required"  placeholder="请输入车辆操作方式" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">座位数</label>
        <div class="layui-input-block">
            <input type="text" id="age" name="car_sitname" lay-verify="required"  placeholder="请输入车辆座位数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label required">日租价格</label>
    <div class="layui-input-block">
        <input type="text" id="birthday" name="c_price" lay-verify="required"  placeholder="车辆日租价格 "value="" class="layui-input">
    </div>
</div>
    <div class="layui-form-item">
        <label class="layui-form-label required">库存余量</label>
        <div class="layui-input-block">
            <input type="text" id="c_number" name="c_number" lay-verify="required" lay-reqtext="库存余量至少为一台" placeholder="请输入库存" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">图片</label>
        <div class="layui-input-block">
            <input type="text" id="car_picture" name="car_picture" lay-verify="required" placeholder="请插入图片" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../layui/layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script>
//     $(function (){
//
//         var teacherid;
//         var classfiyid;
//         var id = window.localStorage.getItem("uid");
//         console.log(111)
//         console.log(id)
//         console.log(1111)
//         $.ajax({
//             url: "/User/getUserByUid/"+id ,
//             dataType:"json",
//             type: 'post',
//             contentType: 'application/json',
//
//             success:function (res){
//                 var data =res
//                 console.log(data);
//                 $("#uid").val(data.uid);
//                 $("#name").val(data.name);
//                 $("#pass").val(data.pass);
//                 $("#age").val(data.age);
//                 $("#birthday").val(data.birthday);
// //                $("#demo1").attr("src",data.coursePic);
// //                debugger;
// //                teacherid=data.teacher.id;
// //                classfiyid=data.classfiy.id;
// //                findClassAndTeacher(classfiyid,teacherid);
//             }
//         })
//     })

    // function findClassAndTeacher(classfiyid,teacherid){
    //     $.ajax({
    //         url: "/classfiy/findAll",
    //         dataType:"json",
    //         success:function (res){
    //             console.log(res.data);
    //             //来去动态赋值给select 选择框
    //             $.each(res.data,function (index,item){
    //                 debugger;
    //                 if (item.id==classfiyid){
    //                     console.log(classfiyid);
    //                     $("#courseClassfiy").append(new Option(item.courseClassifyName,item.id,false,true))
    //                 }else{
    //                     $("#courseClassfiy").append(new Option(item.courseClassifyName,item.id))
    //                 }
    //
    //             })
    //         }
    //     })

    //     $.ajax({
    //         url: "/teacher/findAll",
    //         dataType:"json",
    //         success:function (res){
    //             $.each(res.data,function (index,item){
    //                 if (teacherid==item.id){
    //                     console.log(classfiyid);
    //                     $("#teacherSelect").append(new Option(item.teacherName,item.id,false,true))
    //                 }else{
    //                     $("#teacherSelect").append(new Option(item.teacherName,item.id))
    //                 }
    //
    //             })
    //         }
    //     })
    // }
</script>
<script>
    layui.use(['form','upload', 'element'], function () {

        var form = layui.form,
            upload = layui.upload,
            element = layui.element,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data.field)
            $.ajax({
                url:'/admin/assNewCar',
                data:JSON.stringify(data.field),
                type:"post",
                contentType:"application/json",
                dataType:"json",
                success:function (res){
                console.log(res);
                    if (res==true){
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        location.href='index.html';

                    }
                }
            })
            console.log(11111);
            alert("修改成功");
            // location.href="/getAllUser.html";
            form.render("select");
            // return false;

        });


        //重新加载select 标签
        form.render("select");


        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/course/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });

                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                $("#imgUrl").val(res.data);
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
    });
</script>
</body>
</html>